package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysGames;
import com.ruoyi.system.service.ISysGamesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 竞赛信息Controller
 * 
 * @author ming
 * @date 2022-02-20
 */
@RestController
@RequestMapping("/system/games")
public class SysGamesController extends BaseController
{
    @Autowired
    private ISysGamesService sysGamesService;

    /**
     * 查询竞赛信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:games:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysGames sysGames)
    {
        startPage();
        List<SysGames> list = sysGamesService.selectSysGamesList(sysGames);
        return getDataTable(list);
    }

    /**
     * 导出竞赛信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:games:export')")
    @Log(title = "竞赛信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysGames sysGames)
    {
        List<SysGames> list = sysGamesService.selectSysGamesList(sysGames);
        ExcelUtil<SysGames> util = new ExcelUtil<SysGames>(SysGames.class);
        util.exportExcel(response, list, "竞赛信息数据");
    }

    /**
     * 获取竞赛信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:games:query')")
    @GetMapping(value = "/{gameId}")
    public AjaxResult getInfo(@PathVariable("gameId") Long gameId)
    {
        return AjaxResult.success(sysGamesService.selectSysGamesByGameId(gameId));
    }

    @PreAuthorize("@ss.hasPermi('system:games:query')")
    @PostMapping(value = "/{gameName}")
    public AjaxResult getInfos(@PathVariable("gameName") String gameName)
    {
        return AjaxResult.success(sysGamesService.selectSysGamesByGameName(gameName));
    }

    /**
     * 新增竞赛信息
     */
    @PreAuthorize("@ss.hasPermi('system:games:add')")
    @Log(title = "竞赛信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysGames sysGames)
    {
        return toAjax(sysGamesService.insertSysGames(sysGames));
    }

    /**
     * 修改竞赛信息
     */
    @PreAuthorize("@ss.hasPermi('system:games:edit')")
    @Log(title = "竞赛信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysGames sysGames)
    {
        return toAjax(sysGamesService.updateSysGames(sysGames));
    }

    /**
     * 删除竞赛信息
     */
    @PreAuthorize("@ss.hasPermi('system:games:remove')")
    @Log(title = "竞赛信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{gameIds}")
    public AjaxResult remove(@PathVariable Long[] gameIds)
    {
        return toAjax(sysGamesService.deleteSysGamesByGameIds(gameIds));
    }
}
